import { APP } from '../_helpers/APP'


function getRouter (rname) {
  return APP.diyapi.get(`/routerget?rname=${rname}`)
    .then(body => {
      const total = body.data ? body.data.length : 0
      return body.data
    })
}

function getYaml () {
  return APP.diyapi.get(`/getyaml`)
    .then(body => {
     return body.data
    })
}
function getupstream () {
  return APP.diyapi.get(`/getupstream`)
    .then(body => {
     return body.data
    }).catch(error=>{
      return Promise.reject(error)
    })
}
function getMiddle (rname) {
  return APP.diyapi.get(`/getmid/${rname}`)
    .then(body => {
     return body.data
    }).catch(error=>{
      return Promise.reject(error)
    })
}



function getSrv (rname) {
  return APP.diyapi.get(`/getsrv/${rname}`)
    .then(body => {
     return body.data
    }).catch(error=>{
      return Promise.reject(error)
    })
}


function getMidlist (rname) {
  return APP.diyapi.get(`/midlist`)
    .then(body => {
     return body.data
    }).catch(error=>{
      return Promise.reject(error)
    })
}



function saveYaml (data) {
  return APP.diyapi.post(`/saveyaml`, data)
    .then(body => {
     return body.data
    }).catch(error=>{
      return Promise.reject(error)
    })
}
function saveService (data) {
  return APP.diyapi.post(`/saveupstream`, data)
    .then(body => {
     return body.data
    }).catch(error => {
       return Promise.reject(error)
     })
}
function saveMiddleware (name,midtype, data) {
  return APP.diyapi.post(`/savemiddleware/${name}/${midtype}`, data)
    .then(body => {
     return body.data
    }).catch(error => {
       return Promise.reject(error)
     })
}


function saveRouter (data) {
  let self=  this
  return APP.diyapi.post(`/saverouter`, data)
    .then(body => {
     return body.data
    }).catch(error=>{
      return Promise.reject(error)
    })
}
export default {
  saveRouter,
  getRouter,
  saveService,
  getMiddle,
  getSrv,
  getupstream,
  saveMiddleware,
  getMidlist,
  getYaml,
  saveYaml
}
